package cn.spark.study.core

import org.apache.spark.SparkConf
import org.apache.spark.SparkContext
/*
 * scala： broadcast广播变量代码实战
 */
object BroadcastVariable {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
      .setAppName("BroadcastVariable")
      .setMaster("local")
      
     val sc = new SparkContext(conf)
     
     val factor = 3
     val broadcastFactor = sc.broadcast(factor)
     
     val numbers = Array(1,2,3,4,5)
     
     sc.parallelize(numbers, 1).map { _ * broadcastFactor.value }.foreach { println }
    
  }
}